home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Utilities / GrowStack / GrowStack.asm next >
Encoding:
Assembly Source File  |  1998-07-30  |  2.7 KB  |  126 lines

  1. ; GrowStack 1.0 : increase the size of a task's stack
  2. ; by Kyzer/CSG (parts stolen from Andreas R. Kleinert's C program)
  3. ; $VER: GrowStack.asm 1.0 (29.07.98)
  4. ;
  5.     incdir    include:
  6.     include    dos/dos.i
  7.     include    exec/memory.i
  8.     include    exec/tasks.i
  9.     include    lvo/dos_lib.i
  10.     include    lvo/exec_lib.i
  11.  
  12. stackf    MACRO    ; stack_symbol, stackelement_symbol
  13.     IFND    \1
  14. \1    set    0
  15.     ENDC
  16. \1    set    \1-4
  17. \2    equ    \1
  18.     ENDM
  19.  
  20.     stackf    stk, stacksize    ; these two filled
  21.     stackf    stk, taskname    ; by ReadArgs()
  22.     stackf    stk, rdargs
  23.  
  24. args=taskname
  25.  
  26. GrowStk    link    a5,#stk
  27.     move.l    4.w,a6
  28.     lea    dosname(pc),a1    ; dos.library v37+
  29.     moveq.l    #37,d0
  30.     jsr    _LVOOpenLibrary(a6)
  31.     move.l    d0,a6
  32.     tst.l    d0
  33.     beq    .nodos
  34.  
  35.     lea    templat(pc),a0
  36.     move.l    a0,d1
  37.     lea    args(a5),a0
  38.     move.l    a0,d2
  39.     clr.l    (a0)+
  40.     clr.l    (a0)+
  41.     moveq    #0,d3
  42.     jsr    _LVOReadArgs(a6)
  43.     move.l    d0,rdargs(a5)
  44.     beq.s    .noargs
  45.  
  46. ; NOTE:    This is NOT a good example of stack swapping, since the OLD stack's
  47. ; buffer will _NEVER_ be deallocated. However, there is no other way to
  48. ; achieve a larger stack for IPrefs/ramlib, and since IPrefs/ramlib usually
  49. ; never will end, this perhaps isn't a problem...
  50.  
  51.     move.l    a6,-(sp)
  52.     moveq    #0,d5            ; d5 = new IoErr (if we set it)
  53.  
  54. ; look for requested task
  55.  
  56.     move.l    4.w,a6
  57.     jsr    _LVOForbid(a6)
  58.     move.l    taskname(a5),a1
  59.     jsr    _LVOFindTask(a6)
  60.     tst.l    d0
  61.     beq.s    .notask
  62.     move.l    d0,a2
  63.  
  64. ; check if stack size is already big enough
  65.  
  66.     move.l    stacksize(a5),a0
  67.     move.l    (a0),d7            ; d7 = STACKSIZE
  68.     addq.l    #3,d7
  69.     and.b    #-4,d7            ; longword aligned size
  70.  
  71.     move.l    TC_SPUPPER(a2),d0
  72.     move.l    d0,d6            ; d6 = TC_UPPER
  73.     sub.l    TC_SPLOWER(a2),d0    ; d0 = oldsize = TC_UPPER-TC_LOWER
  74.     cmp.l    d7,d0            ; cmp STACKSIZE, oldsize
  75.     bcc.s    .done            ; if oldsize >= STACKSIZE then EXIT
  76.  
  77. ; allocate new stack and install
  78.  
  79.     move.l    d7,d0
  80.     moveq    #MEMF_PUBLIC,d1
  81.     jsr    _LVOAllocVec(a6)    ; allocate STACKSIZE bytes
  82.     tst.l    d0
  83.     beq.s    .nomem
  84.     add.l    d0,d7            ; d7 = upper = (lower+STACKSIZE)
  85.     move.l    d7,TC_SPUPPER(a2)    ; set new upper
  86.     move.l    d0,TC_SPLOWER(a2)    ; and lower stack limit
  87.  
  88. ; copy old stack contents (not freed) to new stack
  89.  
  90.     move.l    TC_SPREG(a2),a0        ; a0 = TC_SPREG
  91.     sub.l    a0,d6            ; d6 = inuse = (TC_UPPER-TC_SPREG)
  92.     sub.l    d6,d7            ; d7 = pointer = (upper - inuse)
  93.     move.l    d7,TC_SPREG(a2)
  94.     move.l    d7,a1
  95.     move.l    d6,d0
  96.     jsr    _LVOCopyMem(a6)        ; a0=TC_SPREG, a1=pointer, d0=inuse
  97.     bra.s    .done
  98.  
  99. .notask    moveq    #0,d1
  100.     move.b    #ERROR_OBJECT_NOT_FOUND,d5
  101.     bra.s    .done
  102. .nomem    moveq    #ERROR_NO_FREE_STORE,d5
  103.  
  104. .done    jsr    _LVOPermit(a6)
  105.     move.l    (sp)+,a6
  106.     move.l    d5,d1
  107.     jsr    _LVOSetIoErr(a6)
  108. .noargs    move.l    rdargs(a5),d1
  109.     jsr    _LVOFreeArgs(a6)
  110.  
  111.     jsr    _LVOIoErr(a6)
  112.     move.l    d0,d1
  113.     moveq    #0,d2
  114.     jsr    _LVOPrintFault(a6)
  115.  
  116.     move.l    a6,a1
  117.     move.l    4.w,a6
  118.     jsr    _LVOCloseLibrary(a6)
  119. .nodos    unlk    a5
  120.     moveq    #0,d0
  121.     rts
  122.  
  123. dosname    dc.b    "dos.library",0
  124. templat    dc.b    "TASKNAME/A,STACKSIZE/N/A",0
  125.     dc.b    "$VER: GrowStack 1.0 (29.07.98)",0
  126.